<template>
  <div class="dashboard-editor-container">
    <div v-if="is_update" class="tip" style="background-color: #fdf6ec;border-left: 5px solid #e6a23c;">
      <p>
        {{ $t("dashboard.admin.index.update.new_version_detected") }}，<el-link :underline="false" type="primary"
          @click="goPush('/maintain/updateDetail')">{{ $t("dashboard.admin.index.update.update_immediately") }}</el-link>
      </p>
    </div>
    <div>
      <el-radio-group v-model="radio1" @change="handleRadioChange">
        <el-radio-button label="当日" />
        <el-radio-button label="月度" />
      </el-radio-group>
      <template v-if="radio1 == '月度'">
        <el-date-picker v-model="value2" type="month" value-format="yyyy-MM" placeholder="选择月" />
        <el-button type="primary" @click="handleSearch">查询</el-button>
      </template>
    </div>
    <el-row :gutter="40" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" @click="goPush('/userManagement/member/memberList')">
          <div class="card-panel-icon-wrapper icon-message">
            <svg-icon icon-class="visitor" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              {{ $t("dashboard.admin.index.daily_number_user") }}
            </div>
            <!-- <count-to :end-val="options.user" class="card-panel-num" /> -->
            <span class="card-panel-num">{{ options.user||0 }}</span>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" @click="goPush('/indentManagement/indentList')">
          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="Indent" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              {{ $t("dashboard.admin.index.day_order_number") }}
            </div>
            <!-- <count-to :start-val="0" :end-val="options.indent" :duration="3000" class="card-panel-num" /> -->
            <span class="card-panel-num">{{ options.indent||0 }}</span>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-money">
            <!-- <svg-icon icon-class="money" class-name="card-panel-icon" /> -->
            <svg id="mx_n_1710216329949" style="width: 50px;height: 50px;background: #f4516c;
    border-radius: 50%;" t="1710216329948" class="icon" viewBox="0 0 1024 1024" version="1.1"
              xmlns="http://www.w3.org/2000/svg" p-id="10894" width="200" height="200">
              <path
                d="M512 64c247.4 0 448 200.6 448 448S759.4 960 512 960 64 759.4 64 512 264.6 64 512 64zM354.453 323H304.74a3 3 0 0 0-2.929 3.65L328.557 447H269a6 6 0 0 0-6 6v30a6 6 0 0 0 6 6h68.891l10.223 46H269a6 6 0 0 0-6 6v30a6 6 0 0 0 6 6h88.448l26.736 120.302a6 6 0 0 0 5.857 4.698h44.757a6 6 0 0 0 5.804-4.479L472.187 577h78.392l31.476 120.516a6 6 0 0 0 5.806 4.484h44.51a6 6 0 0 0 5.857-4.695L665.042 577H755a6 6 0 0 0 6-6v-30a6 6 0 0 0-6-6h-80.597l10.253-46H755a6 6 0 0 0 6-6v-30a6 6 0 0 0-6-6h-60.983l26.823-120.347a3 3 0 0 0-2.928-3.653h-49.7a6 6 0 0 0-5.881 4.809L638.188 447h-71.286l-31.047-120.25a5 5 0 0 0-4.841-3.75h-39.61a5 5 0 0 0-4.844 3.759L455.745 447h-71.023l-24.39-119.203a6 6 0 0 0-5.879-4.797z m257.402 254l-4.703 23.222-0.244 2.603-0.244-1.822L600.467 577h11.388z m-189.426 0l-5.95 23.222-0.245 1.301v-0.014a5 5 0 0 0-0.101-1.002L411.322 577h11.107z m22.553-88l-11.789 46h-30.465l-9.412-46h51.666z m184.698 0l-9.317 46h-30.74l-11.877-46h51.934z m-102.085 0l12.014 46h-56.415l12.055-46h32.346z m-15.413-59.016L516.625 447h-10.368l4.46-17.016h1.465z"
                fill="#ffffff" p-id="10895" />
            </svg>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              {{ $t("dashboard.admin.index.gross_revenue_today") }}
            </div>
            <!-- <count-to :start-val="0" :end-val="options.income/100" :duration="3000" class="card-panel-num" /> -->
            <span v-if="options.income" class="card-panel-num">{{
              options.income / 100
            }}</span>
            <span v-else class="card-panel-num">{{ 0 }}</span>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="expenditure" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              {{ $t("dashboard.admin.index.total_expenditure_today") }}
            </div>
            <!-- <count-to :start-val="0" :end-val="options.expend/100" :duration="3000" class="card-panel-num" /> -->
            <span v-if="options.expend" class="card-panel-num">{{
              options.expend / 100
            }}</span>
            <span v-else class="card-panel-num">{{ 0 }}</span>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" @click="goPush('/indentManagement/indentList')">
          <div class="card-panel-icon-wrapper icon-shopping">
            <svg-icon icon-class="shipments" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              {{ $t("dashboard.admin.index.wait_delivery_amount") }}
            </div>
            <!-- <count-to :start-val="0" :end-val="options.send" :duration="3000" class="card-panel-num" /> -->
            <span class="card-panel-num">{{ options.send ||0 }}</span>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="goods" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              {{ $t("dashboard.admin.index.understock") }}
            </div>
            <div class="card-panel-num">{{ options.inventoryLess||0 }}</div>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24" style="padding-bottom: 20px;">

        <el-card v-if="radio1 == '当日'" shadow="hover">
          <broken-lin-more v-loading="analyze_loading" ref="line" :char-data="pandectData"
            :id="'c1'" :title="'当日统计'" />
        </el-card>
        <el-card v-if="radio1 == '月度'" shadow="hover">
          <broken-lin-more1 v-loading="analyze_loading" ref="line" :char-data="pandectData"
            :id="'c2'" :title="'月度统计'" />
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import BrokenLinMore from '@/components/G2/G2Plot/BrokenLinMore.vue'
import BrokenLinMore1 from '@/components/G2/G2Plot/BrokenLinMore1.vue'

import CountTo from 'vue-count-to'
import { indexList } from '@/api/index'
export default {
  name: 'DashboardAdmin',
  components: {
    BrokenLinMore,
    BrokenLinMore1,
    CountTo
  },
  data() {
    return {
      listLoading: false,
      options: [],
      analyze_loading: false,
      pandectData: [],
      is_update: false,
      radio1: '当日',
      value2: ''
    }
  },
  created() {
    this.getList()
    this.getUpdate()
  },
  methods: {
    getUpdate() {
      if (sessionStorage.getItem('update_info')) {
        const data = JSON.parse(sessionStorage.getItem('update_info'))
        if (data.new_version !== data.version) {
          this.is_update = true
        }
      }
    },
    getList() {
      this.listLoading = true
      this.analyze_loading = true
      indexList({ datetime: this.value2 }).then(response => {
        this.options = response.data
        this.pandectData = response.data.chart
        this.$nextTick(() => {
          // this.$refs.line && this.$refs.line.updateData(this.pandectData)
        })
        this.listLoading = false
        this.analyze_loading = false
      })
    },
    handleSearch() {
      if (!this.value2) {
        this.$message.warning('请选择日期')
      }
      this.getList()
    },
    handleRadioChange(e) {
      console.log('🤡 ~ e:', e)
      this.radio1 = e
      if (e === '当日') {
        this.value2 = ''
        this.getList()
      } else {
        this.pandectData = []
        this.options = []
      }
    },
    goPush(url) {
      this.$router.push({ path: url })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3;
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3;
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 15px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

.ll {
  line-height: 45px;
  height: 45px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  word-break: break-all;
  counter-increment: counter_ll;
}

.ll:before {
  content: counter(counter_ll) ".";
}
</style>
